/**
 * @file    wm_type_def.h
 *
 * @brief   WM type redefine
 *
 * @author  winnermicro
 *
 * Copyright (c) 2015 Winner Microelectronics Co., Ltd.
 */
#ifndef __WM_TYPE_DEF_H__
#define __WM_TYPE_DEF_H__


#include <stdint.h>
#include <stdbool.h>

typedef enum
{
  HAL_OK       = 0x00U,
  HAL_ERROR    = 0x01U,
  HAL_BUSY     = 0x02U,
  HAL_TIMEOUT  = 0x03U
} HAL_StatusTypeDef;

typedef enum
{
  HAL_UNLOCKED = 0x00U,
  HAL_LOCKED   = 0x01U
} HAL_LockTypeDef;

typedef enum 
{
  RESET = 0, 
  SET = !RESET
} FlagStatus, ITStatus;

#define UNUSED(X) (void)X 

#ifndef NULL
#define NULL ((void *)0)
#endif

#define HAL_MAX_DELAY      0xFFFFFFFF

#define HAL_IS_BIT_SET(REG, BIT)         (((REG) & (BIT)) != 0U)
#define HAL_IS_BIT_CLR(REG, BIT)         (((REG) & (BIT)) == 0U)

typedef unsigned long                   rt_ubase_t;     /**< Nbit unsigned CPU related data type */
typedef unsigned int                    rt_uint32_t;    /**< 32bit unsigned integer type */
#define RT_NULL                         (0)
typedef long                            rt_base_t;      /**< Nbit CPU related date type */
typedef rt_base_t                       rt_err_t;       /**< Type for error number */

typedef unsigned char                   rt_uint8_t;     /**<  8bit unsigned integer type */

#define RT_ALIGN_DOWN(size, align)      ((size) & ~((align) - 1))

rt_uint8_t *rt_hw_stack_init(void       *entry,
                             void       *parameter,
                             rt_uint8_t *stack_addr,
                             void       *exit);

rt_base_t rt_hw_interrupt_disable(void);
void rt_hw_interrupt_enable(rt_base_t level);

/*
 * Context interfaces
 */
void rt_hw_context_switch(rt_ubase_t from, rt_ubase_t to);
void rt_hw_context_switch_to(rt_ubase_t to);
void rt_hw_context_switch_interrupt(rt_ubase_t from, rt_ubase_t to);

#endif
